import 'dart:convert';
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/scoped_model/auth.dart';
import 'package:flutter_app/utils/dio_http.dart';
import 'package:flutter_app/utils/scoped_model_helper.dart';

Future<String> uploadImages(List<File> files, BuildContext context) async {
  var token = ScopedHelperModel.getModel<AuthModel>(context).token;
  if (files.isEmpty) {
    return Future.value('');
  }

  FormData formData = FormData();
// var formData = FormData.fromMap({
//     'file': await MultipartFile.fromFile('./text.txt', filename: 'upload.txt')
//   });
  for (int i = 0; i < files.length; i++) {
    formData.files.add(MapEntry(
        "file", await MultipartFile.fromFile(files[i].path.toString())));
  }
  var res =
      await DioHttp.of(context).postFormData('/houses/image', formData, token);
  var resMap = json.decode(res.toString())["body"];
  String images = List<String>.from(resMap).join('|');
  return Future.value('');
}
